package com.lcf.system.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.lcf.framework.vo.PageVO;
import com.lcf.system.dto.SysOrderDTO;
import com.lcf.system.query.SysOrderPageQuery;
import com.lcf.system.service.SysOrderService;
import com.lcf.system.vo.SysOrderPageVO;
import com.lcf.system.vo.SysOrderVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单(SysOrder)表控制层
 *
 * @author lcf
 * @since 2025-05-02 11:55:03
 */
@Tag(name = "订单")
@RestController
@RequestMapping("sysOrder")
public class SysOrderController {
    @Resource
    private SysOrderService sysOrderService;

    /**
     * 下单
     */
    @Operation(summary = "下单")
    @SaCheckPermission("sysOrder:saveOrder")
    @PostMapping
    public boolean saveOrder(@RequestBody @Validated SysOrderDTO dto) {
        return sysOrderService.saveOrder(dto);
    }

    /**
     * 购物车下单
     */
    @Operation(summary = "购物车下单")
    @SaCheckPermission("sysOrder:saveCartOrder")
    @PostMapping("cart")
    public boolean saveCartOrder(@RequestBody @Schema(description = "购物车id集合") List<Long> cartIdList) {
        return sysOrderService.saveCartOrder(cartIdList);
    }

    /**
     * 团购下单
     */
    @Operation(summary = "团购下单")
    @SaCheckPermission("sysOrder:saveGroupOrder")
    @PostMapping("group/{ruleId}")
    public boolean saveGroupOrder(@PathVariable(value = "ruleId") @Schema(description = "团购规则id") long ruleId) {
        return sysOrderService.saveGroupOrder(ruleId);
    }

    /**
     * 我的订单
     */
    @Operation(summary = "我的订单")
    @SaCheckPermission("sysOrder:page")
    @GetMapping("page")
    public PageVO<SysOrderPageVO> page(SysOrderPageQuery query) {
        return sysOrderService.page(query);
    }

    /**
     * 农户查看订单列表
     */
    @Operation(summary = "农户查看订单列表")
    @SaCheckPermission("sysOrder:pageByFarmer")
    @GetMapping("pageByFarmer")
    public PageVO<SysOrderPageVO> pageByFarmer(SysOrderPageQuery query) {
        return sysOrderService.pageByFarmer(query);
    }
    /**
     * 团长查看订单列表
     */
    @Operation(summary = "团长查看订单列表")
    @GetMapping("pageByLeader")
    public PageVO<SysOrderPageVO> pageByLeader(SysOrderPageQuery query) {
        return sysOrderService.pageByLeader(query);
    }

    /**
     * 订单详情
     */
    @Operation(summary = "订单详情")
    @SaCheckPermission("sysOrder:getDetail")
    @GetMapping("{id}")
    public SysOrderVO getDetail(@PathVariable @Schema(description = "订单id") long id) {
        return sysOrderService.getDetail(id);
    }

    /**
     * 根据订单编号查询
     */
    @Operation(summary = "根据订单编号查询")
    @SaCheckPermission("sysOrder:getByOrderNo")
    @GetMapping("getByOrderNo/{orderNo}")
    public SysOrderVO getByOrderNo(@PathVariable @Schema(description = "订单编号") String orderNo) {
        return sysOrderService.getByOrderNo(orderNo);
    }

    /**
     * 备货中
     */
    @Operation(summary = "备货中")
    @SaCheckPermission("sysOrder:stocking")
    @PostMapping("stocking/{id}")
    public boolean stocking(@PathVariable @Schema(description = "订单id") long id) {
        return sysOrderService.stocking(id);
    }

    /**
     * 待取货
     */
    @Operation(summary = "待取货")
    @SaCheckPermission("sysOrder:pickUp")
    @PostMapping("pickUp/{id}")
    public boolean pickUp(@PathVariable @Schema(description = "订单id") long id) {
        return sysOrderService.pickUp(id);
    }

    /**
     * 已取货
     */
    @Operation(summary = "已取货")
    @SaCheckPermission("sysOrder:pickedUp")
    @PostMapping("pickedUp/{id}")
    public boolean pickedUp(@PathVariable @Schema(description = "订单id") long id) {
        return sysOrderService.pickedUp(id);
    }

    /**
     * 取消订单
     */
    @Operation(summary = "取消订单")
    @SaCheckPermission("sysOrder:cancel")
    @PostMapping("cancel/{id}")
    public boolean cancel(@PathVariable @Schema(description = "订单id") long id) {
        return sysOrderService.cancel(id);
    }

    /**
     * 退货
     */
    @Operation(summary = "退货")
    @SaCheckPermission("sysOrder:back")
    @PostMapping("back/{id}")
    public boolean back(@PathVariable @Schema(description = "订单id") long id) {
        return sysOrderService.back(id);
    }

    /**
     * 配送中
     */
    @Operation(summary = "配送中")
    @SaCheckPermission("sysOrder:delivery")
    @PostMapping("delivery/{id}")
    public boolean delivery(@PathVariable @Schema(description = "订单id") long id) {
        return sysOrderService.delivery(id);
    }

    /**
     * 已送达
     */
    @Operation(summary = "已送达")
    @SaCheckPermission("sysOrder:delivered")
    @PostMapping("delivered/{id}")
    public boolean delivered(@PathVariable @Schema(description = "订单id") long id) {
        return sysOrderService.delivered(id);
    }

    /**
     * 付款
     */
    @Operation(summary = "付款")
    @SaCheckPermission("sysOrder:pay")
    @PostMapping("pay/{id}")
    public boolean pay(@PathVariable @Schema(description = "订单id") long id) {
        return sysOrderService.pay(id);
    }
}

